// smartclass/pages/editDormitorytype/editDormitorytype.js
const _wx = require('../../../utils/util.js');
import Toast from '@vant/weapp/toast/toast';
Page({
  /**
   * 页面的初始数据
   */
  data: {
    id:'',
    username: "", 
    nums: 1,
    bedrule: 0,
    capacity: 1,
    memo: "",
    showPicker: false,
    fieldValue: "",
    columns: [{
        text: "不区分上下铺",
        value: 0
      },
      {
        text: "初始编号为上铺",
        value: 1
      },
      {
        text: "初始编号为下铺",
        value: 2
      },
    ],
  },
  onConfirm(selectedOptions) {
    this.setData({
      showPicker: false
    })
    this.setData({
      fieldValue: selectedOptions.detail.value.text
    })
    this.setData({
      bedrule: selectedOptions.detail.value.value
    })
  },
  onChange(event) {
    console.log(event.detail);
    this.setData({
      nums: event.detail
    })
  },
  onChanges(event) {
    this.setData({
      capacity: event.detail
    })
  },
  onCancel() {
    this.setData({
      showPicker: false
    })
  },
  notification() {
    this.setData({
      showPicker: true
    })
  },
  dormdormtypeupdate() {
    const that = this
    _wx.getData('admin/dorm/dormtype/update', 'POST', {
      id: this.data.id,
      name: this.data.username,
      init_num: this.data.nums,
      bed_rule: this.data.bedrule,
      capacity: this.data.capacity,
      memo: this.data.memo
    }, function (res) {
      if (res.code == 0) {
        Toast.success('修改成功');
        setTimeout(function () {
          wx.redirectTo({
            url: '../Dormitorytypepage/Dormitorytypepage',
          })
        }, 2000);
      }
    });
  },
  submit() {
    this.dormdormtypeupdate()
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({id:options.id})
    this.setData({
      username: decodeURIComponent(options.name)
    })
    this.setData({
      nums: options.init_num
    })
    this.setData({
      fieldValue: options.bed_rule == 0 ? "不区分上下铺" : options.bed_rule == 1 ? "初始编号为上铺" : options.bed_rule == 2 ? "初始编号为下铺" : ''
    })
    this.setData({
      capacity: options.capacity
    })
    this.setData({
      memo: decodeURIComponent(options.memo)
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})